//
//  AppDelegate.m
//  LimitFree
//
//  Created by lijinghua on 16/2/29.
//  Copyright © 2016年 lijinghua. All rights reserved.
//

#import "AppDelegate.h"
#import "LimitFreeTabBarViewController.h"
#import "UMSocial.h"
#import "UMSocialWechatHandler.h"

//SSO:单点登录，使用第三方的登陆系统（譬如QQ，新浪微博账号）来作为我们应用程序的账号，这种登陆方式称为单点登录

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)initUMeng{
     [UMSocialData setAppKey:UMeng_AppKey];
}

- (void)initWeChat
{
    //AppId 和 appSecet 是在微信开放平台注册应用后返回的
    //url:通常是自己的官网
    [UMSocialWechatHandler setWXAppId:@"wxd930ea5d5a258f4f" appSecret:@"db426a9829e4b49a0dcac7b4162da6b6" url:@"http://www.umeng.com/social"];
}

//设置URL Scheme，目的是别的应用程序（微信）,通过URL Scheme 把我的应用程序启动

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //初始化UMeng
    [self initUMeng];
    //初始化微信
    [self initWeChat];
    
    self.window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    //设置根视图
    self.window.rootViewController = [self createRootViewController];
    [self.window makeKeyAndVisible];
    return YES;
}

- (UIViewController*)createRootViewController{
    return [[LimitFreeTabBarViewController alloc]init];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

//以前使用，目前已废弃
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return [UMSocialSnsService handleOpenURL:url];
}

//当别的应用程序（微信）打开我们的程序时调用的代理方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    BOOL result = [UMSocialSnsService handleOpenURL:url];
    if (result == FALSE) {
        //调用其他SDK，例如支付宝SDK等
    }
    return result;
}

@end
